from django.db import models


# Create your models here.


class Book(models.Model):
    name = models.CharField(verbose_name="书名", max_length=30)
    intro = models.CharField(verbose_name="简介", max_length=100, blank=True, null=True)
    status = models.BooleanField(verbose_name="状态", choices=(
        (True, "连载中"),
        (False, "已完结")
    ), default=True, blank=True, null=True)
    latest_chapter = models.CharField(verbose_name="最新章节", max_length=30)
    last_update = models.DateTimeField(verbose_name="最近更新日期", auto_now_add=True, blank=True, null=True)
    last_update_simple = models.CharField(verbose_name="最近更新日期（简）", max_length=30, blank=True, null=True)
    category = models.ForeignKey(verbose_name="分类", to="Category", on_delete=models.CASCADE)
    author = models.ForeignKey(verbose_name="作者", to="Author", on_delete=models.CASCADE)
    tag = models.ManyToManyField(verbose_name="标签", to="Tag")

    class Meta:
        verbose_name = "图书"
        verbose_name_plural = "图书"

    def __str__(self):
        return self.name


class Category(models.Model):
    name = models.CharField(verbose_name="分类名", max_length=30)

    class Meta:
        verbose_name = "分类"
        verbose_name_plural = "分类"

    def __str__(self):
        return self.name


class Author(models.Model):
    name = models.CharField(verbose_name="作者名", max_length=30)

    class Meta:
        verbose_name = "作者"
        verbose_name_plural = "作者"

    def __str__(self):
        return self.name


class Tag(models.Model):
    tag = models.CharField(verbose_name="标签", max_length=30)

    class Meta:
        verbose_name = "标签"
        verbose_name_plural = "标签"

    def __str__(self):
        return self.tag


class RecommendIndex(models.Model):
    name = models.CharField(verbose_name="书名", max_length=30)

    class Meta:
        verbose_name = "首页推荐"
        verbose_name_plural = "首页推荐"

    def __str__(self):
        return self.name


class RecommendIndexChapter(models.Model):
    chapter = models.CharField(verbose_name="章节名", max_length=30)
    name = models.ForeignKey(verbose_name="书名", to="RecommendIndex", on_delete=models.CASCADE)

    class Meta:
        verbose_name = "首页推荐图书章节"
        verbose_name_plural = "首页推荐图书章节"

    def __str__(self):
        return self.chapter


class LatestIndex(models.Model):
    name = models.CharField(verbose_name="书名", max_length=30, unique=True)

    class Meta:
        verbose_name = "首页最新"
        verbose_name_plural = "首页最新"

    def __str__(self):
        return self.name


class CategoryPageRecommend(models.Model):
    name = models.CharField(verbose_name="书名", max_length=30)
    category = models.IntegerField(verbose_name="分类编号", max_length=30)

    class Meta:
        verbose_name = "不同分类推荐"
        verbose_name_plural = "不同分类推荐"

    def __str__(self):
        return self.name


class CategoryPageList(models.Model):
    name = models.CharField(verbose_name="书名", max_length=30)
    latest_chapter = models.CharField(verbose_name="最新章节", max_length=30)
    author = models.CharField(verbose_name="作者名", max_length=30)
    number = models.IntegerField(verbose_name="字数", max_length=30)
    last_update_simple = models.CharField(verbose_name="最近更新日期（简）", max_length=30)
    status = models.CharField(verbose_name="状态", max_length=30)
    category = models.IntegerField(verbose_name="分类编号", max_length=30)
